<template>
<div>
  <el-dialog title="新增界面" :visible.sync="showFlag" @close="closeDialog" width="40%">
    <el-form ref="addDeviceForm" :model="addDeviceForm" :rules="addDeviceRules" label-width="80px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="房间编号" prop="rid">
            <el-input v-model="addDeviceForm.rid" placeholder="请输入房间编号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公寓编号" prop="apt_id">
            <el-input v-model="addDeviceForm.apt_id" placeholder="请输入公寓编号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="设备名称" prop="name">
            <el-input v-model="addDeviceForm.name" placeholder="请输入设备名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="设备价格" prop="price">
            <el-input v-model="addDeviceForm.price" placeholder="请输入设备价格"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="设备状态" prop="dstatus">
            <el-select v-model="addDeviceForm.dstatus" placeholder="请选择设备状态" style="width: 100%">
              <el-option label="使用中" value="10"></el-option>
              <el-option label="维护中" value="20"></el-option>
              <el-option label="损坏" value="30"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报修状态" prop="dstatus">
            <el-select v-model="addDeviceForm.dstatus" placeholder="请选择保修状态" style="width: 100%">
              <el-option label="未报修" value="10"></el-option>
              <el-option label="已报修" value="20"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item class="dialog-footer" align="center">
        <el-button type="success" @click="onSave('addDeviceForm')">保 存</el-button>
        <el-button @click="onCancel('addDeviceForm')">取 消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</div>
</template>

<script>
export default {
name: "addDevice",
  data(){
  return{
    addDeviceForm:{
      rid:'',
      apt_id:'',
      name:'',
      price:'',
      dstatus:'',
      report:''
    },
    addDeviceRules: {
      id:[{required:true,message: '请输入设备编号',trigger: 'blur'}],
      rid:[{required:true,message: '请输入房间编号',trigger: 'blur'}],
      apt_id:[{required:true,message: '请输入公寓编号',trigger: 'blur'}],
      dstatus:[{required:true,message: '请输入公寓编号',trigger: 'blur'}],
      report:[{required:true,message: '请输入公寓编号',trigger: 'blur'}]
    },
    showFlag:false,
  }
  },
  methods:{
    //初始化
    init(){
      this.showFlag=true
    },
    //关闭对话框的回调函数
    closeDialog(){
      this.$refs.addDeviceForm.resetFields()
    },
    //保存
    onSave(){
      this.$refs.addDeviceForm.validate( async valid=>{
        if(valid){
          const {data:res}=await this.$http.post('/rDevice/insertRDevice',this.addDeviceForm)
          if(res.code !=200) return this.$message.error('添加设备信息失败！')
            this.$message.success('添加设备信息成功~')
        }
      })
      this.$emit('addClickBack')
      this.showFlag=false
    },
    //取消
    onCancel(){
      this.showFlag=false
      this.$refs.addDeviceForm.resetFields()
    }
  }
}
</script>

<style scoped>

</style>